/*
 * frontbuttons.c
 *
 * Created: 02.01.2012 16:58:55
 *  Author: Halfmann
 */ 

#include <avr/interrupt.h>
#include "frontbuttons.h"
#include "globals.h"


void buttons_init()
{
	//Buttons als Eingaenge - Auswertung erfolgt in den Interrupts
	DDRD &= ~(1<<PD2);
	DDRD &= ~(1<<PD3);
	DDRB &= ~(1<<PB2);
	
	//Interne Pull-Ups aktivieren
	PORTD |= (1<<PD2) | (1<<PD3);
	PORTB |= (1<<PB2);
	
	//Interrupt wird bei fallender Flanke ausgeloest!
	EICRA |= (1<<ISC01) | (1<<ISC11) | (1<<ISC21);
	
	//Externe Interrupts aktivieren
	EIMSK |= (1<<INT0) | (1<<INT1) | (1<<INT2);
}

//Button 1 (Mode)
ISR(INT0_vect)
{
	LCD_BACKL_SWITCH_ON;
	
	//Durchschaltung der Modes
	if (mode < MODES_COUNT)
	{
		breakAnimation = 1;
		mode++;
	}		
	else if(mode == MODES_COUNT)
	{
		breakAnimation = 1;
		mode = 1;
	}		
}

//Button2 (Up)
ISR(INT1_vect)
{
	increaseActiveEffect();
}

//Button3 (Down)
ISR(INT2_vect)
{
	decreaseActiveEffect();
}